<template>
  <div class="main clearfix">
    <!-- 查询 -->
    <section class="section_wrap wrap_te">
      <el-form
        :inline="true"
        style="text-align: left"
        :model="query"
        ref="query"
        class="query clearfix"
      >
        <el-form-item label="关键词:" prop="keyWorld">
          <el-input
            placeholder="订单号、客户名称、客户手机"
            v-model="query.keyWorld"
          ></el-input>
        </el-form-item>
        <el-form-item label="订单状态:" prop="orderStatus">
          <el-select v-model="query.orderStatus" placeholder="请选择">
            <el-option
              v-for="item in orderStatusData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="提成核算:" prop="calculation">
          <el-select v-model="query.calculation" placeholder="请选择">
            <el-option
              v-for="item in calculationStateData"
              :key="item.itemValue"
              :label="item.itemText"
              :value="item.itemValue"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="录入日期:" prop="grantTime">
          <el-date-picker
            v-model="query.grantTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:210px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="button">
          <el-button v-no-more-click type="danger" @click="emptyFun"
            >清空</el-button
          >
          <el-button v-no-more-click type="primary" @click="queryFun"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </section>
    <section class="section_wrap">
      <el-form>
        <el-row>
          <el-col :xl="24">
            <el-form-item class="btn">
              <el-button @click="newSingLe">+录入新单</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table
        :data="tableData"
        :inline="true"
        border
        stripe
        style="width: 100%"
        :row-key="getRowKey"
        ref="multipleTable"
        @selection-change="changeFun"
      >
        <el-table-column
          type="selection"
          :reserve-selection="true"
          width="36"
          class-name="checkBox"
        ></el-table-column>
        <el-table-column
          prop="orderNumber"
          label="业务单号"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="customerName"
          label="客户名称"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="customerAddress"
          label="客户地区"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="loansMoney"
          label="审批金额(万元)"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="firmName"
          label="归属公司"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="deptName"
          label="归属部门"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongName"
          label="归属人员"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="belongType"
          label="归属人员类型"
          :formatter="translaPersonnel"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="inputTime"
          label="录入日期"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="inputName"
          label="录入人"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="approvalProgress"
          label="审批进展"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="updateTime"
          label="更新日期"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="markUpdate"
          label="更新提醒"
          :formatter="translaMarkUpdate"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          prop="orderStatus"
          label="订单状态"
          :show-overflow-tooltip="true"
        />
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="HasBeen(scope.row)"
              style="color:#45B8EF"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!--    分页-->
      <div class="pagination">
        <span class="title">小计：共{{ this.total }}条数据</span>
        <el-pagination
          background
          layout="prev, pager, next, sizes"
          :total="total"
          :page-size="query.pageSize"
          :page-sizes="[10, 20, 30, 40, 50]"
          :current-page.sync="currentPage"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {
  getEmployee,
  postCompanyEmployList,
  getOrderListBy
} from "../../assets/js/api";
import { GMTToStr } from "../../assets/js/utlis";

export default {
  name: "ValueAdded",
  data() {
    return {
      normalizer(node) {
        //去掉children=[]的children属性
        if (node.children == null) {
          delete node.children;
        }
      },
      describe: {
        describe: ""
      },
      total: null,
      pageNo: 1,
      pages: 0,
      pagesize: 10,
      currentPage: 1,
      query: {
        pageNo: 1,
        pageSize: 10,
        keyWorld: null,
        calculation: null,
        orderStatus: null,
        productId: "",
        grantTime: null
      },
      valQuerryBy: {
        productId: "",
        approvalByMeState: 1
      },
      newNum: "",
      queryVux: {},
      queryData: {},
      suspend: {
        orderNumber: "",
        operationCause: ""
      },
      suspendInf: {
        name: null
      },
      dialogsuspendFun: false,
      queryPersonnel: {
        firmId: null,
        deptId: null
      },
      options: [],
      tableData: [],
      // 订单状态
      orderStatusData: [],
      // 人员类型
      personnelTypeData: [],
      // 是否由我审批
      approvalByMeStateData: [],
      //财务收费状态
      chargeStatus: [],
      // 更新提醒
      markUpdateData: [],
      // 提成核算状态
      calculationStateData: [],
      // 公司数据
      companyData: [],
      // 部门数据
      deptData: [],
      // 人员数据
      personnelData: [],
      ids: [],
      orderExportId: [],
      newsOrderStatus: -2,
      //待放款跳转路径
      tbleadgUrl: "",
      //归档路径
      lendgUrl: "",
      rules: {
        operationCause: [
          { required: true, message: "请填写中止原因", trigger: "blur" }
        ]
      },
      multipleSelection: [],
      select_order_number: "",
      select_orderId: []
    };
  },

  created() {
    this.query.productId = sessionStorage.getItem("productId");
    this.valQuerry.productId = sessionStorage.getItem("productId");
    this.valQuerryBy.productId = sessionStorage.getItem("productId");
    this.getOrderListBy(this.query);
    this.orderStatus();
    this.personnelType();
    this.approvalByMeState();
    this.markUpdate();
    this.calculationState();
  },
  computed: {
    //未处理时是0隐藏
    showNewNum: function() {
      if (this.newNum == 0) {
        return false;
      } else {
        return true;
      }
    },
    //从vueX获取数据
    ...mapState({
      valQuerry: "valueAdd"
    })
  },
  methods: {
    //模糊查询
    getOrderListBy(obj) {
      getOrderListBy(obj).then(res => {
        this.tableData = res.data.records;
        this.pagesize = res.data.size;
        this.pageNo = res.data.current;
        this.total = res.data.total;
        this.pages = res.data.pages;
      });
    },
    newSingLe() {
      // 录入新单
      let pathUrl = this.$route.path;
      this.$router.push({
        path: "/Index/MeitListAdd",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
      sessionStorage.setItem("orderStatus", this.newsOrderStatus);
    },
    // 已录入
    HasBeen(row) {
      let pathUrl = this.$route.path;
      sessionStorage.setItem("orderNumber", row.orderNumber);
      this.$router.push({
        path: "/Index/MeitListView",
        query: { path: pathUrl } //记录跳入录入新单进口路径
      });
    },
    // 订单状态
    orderStatus() {
      getEmployee("order_state").then(res => {
        this.orderStatusData = res.data;
      });
    },
    // 人员类型
    personnelType() {
      getEmployee("emp_type").then(res => {
        this.personnelTypeData = res.data;
      });
    },
    // 是否由我审批
    approvalByMeState() {
      getEmployee("approval_by_me_state").then(res => {
        this.approvalByMeStateData = res.data;
      });
      //财务收费状态chargeStatus
      getEmployee("charge_status").then(res => {
        this.chargeStatus = res.data;
      });
    },
    // 更新提醒
    markUpdate() {
      getEmployee("mark_update").then(res => {
        this.markUpdateData = res.data;
      });
    },
    // 提成核算状态
    calculationState() {
      getEmployee("calculation_state").then(res => {
        this.calculationStateData = res.data;
      });
    },
    // 获取归属人员数据
    postCompanyEmployList() {
      postCompanyEmployList(this.queryPersonnel).then(res => {
        this.personnelData = res.data;
      });
    },
    // 归属人员类型翻译
    translaPersonnel(row) {
      return this.selectDictLabel(this.personnelTypeData, row.belongType);
    },
    // 提成核算状态翻译
    translaCalculation(row) {
      return this.selectDictLabel(
        this.calculationStateData,
        row.calculationState
      );
    },
    // 由我审批翻译
    translaApprovalByMe(row) {
      return this.selectDictLabel(
        this.approvalByMeStateData,
        row.approvalByMeState
      );
    },
    // 更新提醒翻译
    translaMarkUpdate(row) {
      if (row.markUpdate > 0) {
        return "有更新";
      } else {
        return "无更新";
      }
      //return this.selectDictLabel(this.markUpdateData, row.markUpdate);
    },
    // 订单状态翻译
    translaOrderStatus(row) {
      return this.selectDictLabel(this.orderStatusData, row.orderStatus);
    },
    ...mapMutations(["valueQuery"]),
    // 搜索按钮
    queryFun() {
      this.queryData = JSON.parse(JSON.stringify(this.query));
      this.queryData.pageNo = 1;
      this.queryData.productId = sessionStorage.getItem("productId");
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.beginInputTime = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.endInputTime = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      this.valueQuery(this.queryData);
      this.getOrderListBy(this.valQuerry);
      this.currentPage = 1;
      //清空多选
      this.$refs["multipleTable"].clearSelection();
    },
    // 清空按钮
    emptyFun() {
      this.$refs["query"].resetFields();
      this.query.grantTime = null;
      (this.deptData = []),
        (this.personnelData = []),
        (this.queryData = JSON.parse(JSON.stringify(this.query)));
      this.queryData.productId = sessionStorage.getItem("productId");
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.beginInputTime = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.endInputTime = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      //清空多选
      this.$refs["multipleTable"].clearSelection();
      this.valueQuery(this.queryData);
      this.getOrderListBy(this.queryData);
      this.currentPage = 1;
    },
    //分页
    handleCurrentChange(cpage) {
      this.queryData = JSON.parse(JSON.stringify(this.query));
      this.queryData.pageNo = cpage;
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.beginInputTime = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.endInputTime = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      console.log(this.query);
      this.queryData.productId = sessionStorage.getItem("productId");
      this.getOrderListBy(this.queryData);
    },
    handleSizeChange(psize) {
      this.queryData = JSON.parse(JSON.stringify(this.query));
      this.queryData.pageSize = psize;
      //录入日期
      if (this.queryData.grantTime && this.queryData.grantTime[0]) {
        this.queryData.beginInputTime = GMTToStr(this.queryData.grantTime[0]);
        this.queryData.endInputTime = GMTToStr(this.queryData.grantTime[1]);
      }
      delete this.queryData.grantTime;
      this.queryData.productId = sessionStorage.getItem("productId");
      this.getOrderListBy(this.queryData);
    },
    // 批量
    getRowKey(row) {
      return row.orderId;
    },
    changeFun(row) {
      this.ids = row.map(item => item.orderNumber);
      this.orderExportId = row.map(item => item.orderId);

      this.multipleSelection = row;
      this.select_order_number = this.multipleSelection.length;
      this.select_orderId = [];
      if (row) {
        row.forEach(row => {
          if (row) {
            this.select_orderId.push(row.orderNumber);
          }
        });
      }
    }
  },
  watch: {
    total: {
      handler() {
        if (
          this.total == (this.pageNo - 1) * this.pagesize &&
          this.total != 0
        ) {
          this.pageNo -= 1;
          this.queryData.pageNo = this.pageNo;
          //录入日期
          if (this.queryData.grantTime && this.queryData.grantTime[0]) {
            this.queryData.beginInputTime = GMTToStr(
              this.queryData.grantTime[0]
            );
            this.queryData.endInputTime = GMTToStr(this.queryData.grantTime[1]);
          }
          delete this.queryData.grantTime;
          this.valueQuery(this.queryData);
          this.getOrderListBy(this.valQuerry); //获取列表数据
        }
      }
    },
    $route: function(to, from) {
      if (to.path != from.path) {
        // this.queryData.productId = sessionStorage.getItem("productId");
        // this.queryData.pageNo = 1;
        // this.valueQuery(this.queryData);
        // this.getOrderListBy(this.queryData);
        this.emptyFun();
        this.valQuerryBy.productId = sessionStorage.getItem("productId");
        this.currentPage = 1;
      }
    }
  }
};
</script>

<style scoped type="less">
.query .el-form-item {
  position: relative;
  padding-left: 110px;
  box-sizing: border-box;
  width: 320px;
}
.query ::v-deep .el-form-item__label {
  position: absolute;
  width: 110px;
  text-align: right;
  left: 0;
  top: 0;
  line-height: 32px;
  height: 32px;
}
.query ::v-deep .vue-treeselect {
  height: 32px;
}
.query ::v-deep.el-input__icon,
.query ::v-deep.el-range-separator {
  line-height: 24px;
}
.treeSel ::v-deep .vue-treeselect__control {
  height: 32px;
  line-height: 30px;
  overflow: hidden;
}

::v-deep .el-table td {
  padding: 10px 0;
}
::v-deep .el-table th {
  padding: 10px 0;
}
::v-deep .el-button--text {
  width: 40px;
}
::v-deep .el-form--inline .el-form-item__content {
  line-height: 32px;
  width: 100%;
}
::v-deep .btn .el-form-item__content {
  width: 100%;
}
.query ::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}
::v-deep .el-input__icon {
  line-height: 32px;
}
.query .el-select {
  width: 100%;
}
::v-deep .button .el-button {
  width: 80px;
  height: 32px;
  line-height: 0;
}
::v-deep .el-table th > .cell {
  font-weight: bold;
  color: #333;
  font-size: 14px;
}
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td {
  background: rgba(59, 157, 248, 0.1);
}
.main {
  position: relative;
}
::v-deep .el-pagination {
  position: absolute;
  margin-top: 20px;
  right: 0;
}
::v-deep .el-pagination__total {
  visibility: hidden;
}
.title {
  position: absolute;
  left: 0;
  top: 20px;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  line-height: 21px;
}
.btn .el-button {
  float: left;
}
.wrap_te {
  padding: 15px 10px 0 0;
}
.wrap_te .el-form-item {
  margin-bottom: 10px;
}
.el-form-item.button {
  text-align: right;
  width: 100%;
}
.el-table ::v-deep.tips .cell {
  overflow: visible;
}
.el-table ::v-deep.tips sup {
  top: -4px;
  right: 11px;
}
</style>
